//
//  HXTabBarViewController.m
//  百思不得姐
//
//  Created by Hubery on 16/1/12.
//  Copyright © 2016年 Whx. All rights reserved.
//

#import "HXTabBarViewController.h"
#import "XMGEssenceViewController.h"
#import "HXMeViewController.h"
#import "HXFriendViewController.h"
#import "HXNewViewController.h"
#import "HXTabBar.h"
#import "HXNavigationViewController.h"

@interface HXTabBarViewController ()

@end

@implementation HXTabBarViewController


/**
 *
 [UIColor colorWithRed:<#(CGFloat)#> green:<#(CGFloat)#> blue:<#(CGFloat)#> alpha:<#(CGFloat)#>];
 颜色:
 
 24bit颜色: R G B
 * #ff0000
 * #ccee00
 * #000000
 * #ffffff
 
 32bit颜色: ARGB
 * #ff0000ff
 
 常见颜色:
 #ff0000 红色
 #00ff00 绿色
 #0000ff 蓝色
 #000000 黑色
 #ffffff 白色
 
 灰色的特点:RGB一样
 
 1024x1024像素的图片  32bit颜色 (内存大小计算)
 
 1024x1024x32\8 == 1024x1024x4
 1024x1024x24\8 == 1024x1024x3
 */



+ (void)initialize
{
    // 通过appearance统一设置所有UITabBarItem的文字属性
    // 后面带有UI_APPEARANCE_SELECTOR的方法, 都可以通过appearance对象来统一设置
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    /* You may specify the font, text color, and shadow properties for the title in the text attributes dictionary, using the keys found in NSAttributedString.h.
     */

}


- (void)viewDidLoad {
    [super viewDidLoad];
//    UITabBarItem
    

    // 添加子控制器
    [self setupChildVc:[[XMGEssenceViewController alloc] init] title:@"精华" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    
    [self setupChildVc:[[HXNewViewController alloc] init] title:@"新帖" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    
    [self setupChildVc:[[HXFriendViewController alloc] init] title:@"关注" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    HXMeViewController *vc = [[HXMeViewController alloc] initWithStyle:UITableViewStyleGrouped];
    [self setupChildVc:vc title:@"我" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];

    /**
     kvc 是能直接访问成员变量
     对于只读的变量  属性 set 方法不给搞  可以直接赋值到 下划线变量
     */
    [self setValue:[[HXTabBar alloc] init] forKeyPath:@"tabBar"];
}

/**
 * 初始化子控制器
 */
- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 设置文字和图片
    vc.navigationItem.title = title;
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    // 包装一个导航控制器, 添加导航控制器为tabbarcontroller的子控制器
    HXNavigationViewController *nav = [[HXNavigationViewController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];

}

/**
 *  当控制器的 view 已经布局完子控制器 调用
 */
-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    
}

/**
 tabbar 选中图片 会进行一个默认的渲染 为蓝色
 设置不渲染
 也可以在 image.xc 里面舍值图片的 Rencer As
 */

-(void)setupImage
{
    UIImage *image = [UIImage imageNamed:@"tabBar_me_click_icon"];
    image = [image   imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
}

/**
 - (void)setTitleTextAttributes:(nullable NSDictionary<NSString *,id> *)attributes forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
 
 UI_APPEARANCE_SELECTOR 带有这个宏的 就可以用 appearance 方法设置
 */

@end
